<?php
/**
 * User not an administrator, redirect to Home page
 * automatically.
 */
if(!$session->isAdmin()){
   header("Location: ../index.php");
}
else{ ?>
<div id="form_container" style="border:none; width:800px; margin: 10px 78px 0px 78px;">
	<div id="form_text" style="margin:0px;" class="settings">
    	<h2>Users List</h2>
    </div>
    <div id="form_content" class="settings" style="text-align:center">
        <div class="tableFilter">
            <form id="tableFilter" action="" method="post" onsubmit="myTable.filter(this.id); return false;"><b>Filter: </b> 
                <select id="column" class="select">
                    <option value="1">Firstname</option>
                    <option value="2">Lastname</option>
                    <option value="3">Email</option>
                </select>
                <input type="text" id="keyword" />
                <input class="submit" type="submit" value="Search" />
                <input class="submit" type="reset" value="Clear" />
            </form>
        </div>
        
        <!-- The navigation buttons between pages -->
        <?php include('../include/pagination.php');
		if (isset($_POST['orderby'])){
			$orderby=$_POST['orderby'];
		} else {
			$orderby = 'username';
		}
		$result = $pagination->paginatePage("20","users","$orderby");?> 
        
        <!-- The table of users -->
        <table id="myTable" cellpadding="0" cellpadding="0">
            <thead>
                <th axis="string">Username</th>
                <th axis="number">User Level</th>
                <th axis="string">Email</th>
                <th axis="date">Registered</th>
                <th axis="date">Last Login Time</th>
            </thead>
            <tbody>
            	<?php while ($row = $result->fetch()) {
				$timestamp = $row['timestamp'];
				$lastlogin  = date("j M, y, g:i a", $timestamp);
				$regdate = $row['regdate'];
				$reg  = date("j M, y, g:i a", $regdate);		
				echo "<tr><td><a href='main.php?id=6&usertoedit=".$row['username']."'>".$row['username']."</a></td><td>".$row['userlevel']."</td>"
				."<td><a href='mailto:".$row['email']."'>".$row['email']."</a></td><td>"
				.$reg."</td><td>".$lastlogin."</td></tr>";		
				}?>
            </tbody>
            <tfoot>
                <tr style="visibility:hidden">
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
            </tfoot>
        </table>
	</div>
</div>
<script type="text/javascript">
	var myTable = {};
	window.addEvent('domready', function(){
		myTable = new sortableTable('myTable', {overCls: 'over', onClick: function(){}});
	});
</script>

<?php } ?>